﻿@model SMECustomerWebsite.Models.ViewModels.CustomerManager.CustomerPortfolioViewModel
@Html.Action("CustInfo", "System")
<!-- start accordion -->
<div class="">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <div class="x_title">
                    <div class="col-lg-8 col-md-9 col-sm-8">
                        <h2>@SMECustomerWebsite.Core.Resources.Resource.YourCust</h2>
                    </div>
                    <ul class="nav navbar-right panel_toolbox">
                        @Html.Action("BusinessDateInfo", "System", new { name = "TBL_CUSTOMER" })
                        <li>
                            <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    @if (Model.CurrentUser.GroupIdentifier.Equals("3"))
                    {
                        <div class="col-md-6 cm-search-box">
                            @using (Html.BeginForm("ExportDataTotalCustomer", "CustomerManager", FormMethod.Post, new { @class = "sme-form-export" }))
                            {
                                <input type="submit" name="btnExportLicensing" style="width: 140px;" value="Export to excel" id="exportLicensing" class="btn btn-success right" />
                            }
                        </div>
                    }
                    @switch (Model.CurrentUser.GroupIdentifier)
                    {
                        case "1":
                            <table id="cm-customer-total" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                                <thead class="headings" id="tbl_headings">
                                    <tr>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                        <th class="column-title">DAO</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                        <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CusStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CusStatus.ToUpper()</th>
                                        <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatus.ToUpper()</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                            break;
                        case "2":
                        <table id="cm-customer-total" class="custom_table table table-bordered table-striped jambo_table">
                            <thead class="headings" id="tbl_headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CusStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CusStatus.ToUpper()</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatus.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        case "3":
                        <table id="cm-customer-total" class="custom_table table table-bordered table-striped jambo_table">
                            <thead class="headings" id="tbl_headings">
                                <tr>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CusStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CusStatus.ToUpper()</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatus.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        case "4":
                        <table id="cm-customer-total" class="custom_table table table-bordered table-striped jambo_table">
                            <thead class="headings" id="tbl_headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CusStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CusStatus.ToUpper()</th>
                                    <th class="column-title" data-toggle="tooltip" data-placement="top" title="" data-original-title="@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatusDescription">@SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatus.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        default:
                            break;
                    }

                </div>
            </div>
        </div>
    </div>
</div>
<!-- end of accordion -->
@section scripts
{
    <script src="~/Scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var totalColumn = [
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN", "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false },
                        { "sName": "BUSINESS STATUS", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }]
            var totalLenCol = 6;
            var totalCifCol = 0;
            switch (@Model.CurrentUser.GroupIdentifier)
            {
                case 1:
                    totalColumn = [
                           { "sName": "REGION", "bSortable": false },
                           { "sName": "BRANCH", "bSortable": false },
                           { "sName": "DAO", "bSortable": false },
                           { "sName": "MSBO", "bSortable": false },
                           { "sName": "CIF", "bSortable": false },
                           { "sName": "NAME", "bSortable": false },
                           { "sName": "VPB INDUSTRY", "bSortable": false },
                           { "sName": "DATE OPEN", "bSortable": false },
                           { "sName": "CUSTOMER STATUS", "bSortable": false },
                           { "sName": "BUSINESS STATUS", "bSortable": false },
                           { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 10;
                    totalCifCol = 4;
                    break;
                case 2:
                    totalColumn=  [
                        { "sName": "BRANCH", "bSortable": false },
                        { "sName": "DAO", "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN", "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false },
                        { "sName": "BUSINESS STATUS", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 9;
                    totalCifCol = 3;
                    break;
                case 3:
                    totalColumn= [
                        { "sName": "DAO", "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN", "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false },
                        { "sName": "BUSINESS STATUS", "bSortable": false },
                        { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 8;
                    totalCifCol = 2;
                    break;
                default:
                    break;
            }
            var table = $('#cm-customer-total').DataTable({
                "paging": true,
                //fixedHeader: true,
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0, 1, 2,3],
                "sAjaxSource": '@Url.Action("TotalCustomerData", "CustomerManager")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns":totalColumn,
                'fnCreatedRow': function (nRow, aData, iDataIndex) {
                    $(nRow).attr('id', 'my_account_planning' + iDataIndex); // or whatever you choose to set as the id
                    $('td', nRow).eq(totalLenCol).attr('id', 'td_' + iDataIndex + '_action');
                    //$('td', nRow).eq(6).attr('class', 'td_action');
                },
                "aoColumnDefs": [{
                    "sClass": "column-title",
                    "aTargets": [totalLenCol],
                    "mRender": function (data, type, full) {
                        return '<a class=\"btn btn-primary btn-xs\" onclick=\"showCustomerInfo(\'' + full[totalCifCol] + '\');\"><i class="fa fa-info"></i></a>';
                    }
                },{
                    "sClass": "column-title",
                    "aTargets": [totalLenCol-2],
                    "mRender": function (data, type, full) {
                        switch (data){
                            case 'INACTIVE':
                                return '<p style="background:red;color:white;">'+ data+'</p>';
                                break;
                            case 'ACTIVE':
                                return '<p style="background:green;color:white;">'+ data+'</p>';
                            default:
                                return '<p style="background:yellow;">'+ data+'</p>';
                                break;
                        }
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone)');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader)':
                                createFilterDate(column);
                                break;
                            case '@SMECustomerWebsite.Core.Resources.Resource.CusStatus.ToUpper()':
                                createFilterStatus(column,'cust_status_search');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.CustBusinessStatus.ToUpper())':
                                createFilterStatus(column,'business_status_search');
                                break;
                            case '@Html.Raw(@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                                createFilterMSBOName(column, 1);
                                break;
                            case 'DAO':
                                createFilterMSBOName(column, 2);
                                break;
                            default:
                                if (column.index() < totalLenCol) {
                                    createFilterInputText(column);
                                }
                                break;
                        }
                    });
                },
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });
        })
    </script>

    @if (true)
    {
        <script type="text/javascript">
            function startPageTourGuide() {
                var intro = introJs();
                var steps = [
                        {
                            element: '#cm-customer-total',
                            intro: '@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTable',
                            position: 'bottom'
                        },
                        {
                            element: '#cm-customer-total_length',
                            intro: '@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTableLength',
                            position: 'right',
                        },
                        {
                            element: '#tbl_headings',
                            intro: "@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTableSearch",
                            position: 'bottom'
                        },
                        {
                            element: '#cm-customer-total_info',
                            intro: "@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTableInfo",
                            position: 'bottom'
                        },
                        {
                            element: '#cm-customer-total_paginate',
                            intro: "@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTablePaginate",
                            position: 'left'
                        },
                        {
                            element: '#my_account_planning0',
                            intro: "@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTableRow",
                            position: 'bottom'
                        },
                        {
                            element: '#td_0_action',
                            intro: "@SMECustomerWebsite.Core.Resources.Resource.TourGuideAccGenTableRowAction",
                            position: 'left'
                        }
                ];
                intro.setOptions({
                    steps: steps,
                    showProgress: true,
                    scrollToElement: true,
                });
                intro.setOption('tooltipPosition', 'auto');
                intro.setOption('positionPrecedence', ['left', 'right', 'bottom', 'top'])
                intro.start();
            }
        </script>
    }
}